﻿#region 文件信息

/***************************************
** 文件名:	EgoEventCenter
** 版  权:	(C) egogame 
** 创建人:	鱼蛋
** 日  期:	2020.07
** 描  述:	事件中心
***************************************/

#endregion

using System;

#region QuickCode
public static class EgoEventCenterQuickCode
{
    public static void FireEvent(this IEventObject target, string eventName)  
    {
        EgoEventCenter.PostEvent(eventName);
    }
    public static void FireEvent<T>(this IEventObject target, string eventName,T value)
    {
        EgoEventCenter.PostEvent<T>(eventName, value);
    }
    public static void AddEventListener(this IEventObject target, string eventName, EventHandle handle)
    {
        EgoEventCenter.AddListener(eventName, handle);
    }
    public static void AddEventListener<T>(this IEventObject target, string eventName, EventHandle<T> handle)
    {
        EgoEventCenter.AddListener<T>(eventName, handle);
    }
    public static void RemoveEventListener(this IEventObject target, string eventName, EventHandle handle)
    {
        EgoEventCenter.RemoveListener(eventName, handle);
    }
    public static void RemoveEventListener<T>(this IEventObject target, string eventName, EventHandle<T> handle)
    {
        EgoEventCenter.RemoveListener<T>(eventName, handle);
    }
}

#endregion

public static class EgoEventCenter
{
    public static EventCenter Default = new EventCenter();

    /// <summary>
    /// 发送事件
    /// </summary>
    /// <param name="eventName">事件名</param>
    public static void PostEvent(string eventName)
    {
        Default.PostEvent(eventName);
    }

    /// <summary>
    /// 发送事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="value"></param>
    /// <typeparam name="T"></typeparam>
    public static void PostEvent<T>(string eventName, T value)
    {
        Default.PostEvent<T>(eventName, value);
    }

    /// <summary>
    /// 发送事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="value1"></param>
    /// <param name="value2"></param>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public static void PostEvent<T1, T2>(string eventName, T1 value1, T2 value2)
    {
        Default.PostEvent<T1, T2>(eventName, value1, value2);
    }

    /// <summary>
    /// 发送事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="value1"></param>
    /// <param name="value2"></param>
    /// <param name="value3"></param>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    public static void PostEvent<T1, T2, T3>(string eventName, T1 value1, T2 value2, T3 value3)
    {
        Default.PostEvent(eventName, value1, value2, value3);
    }

    /// <summary>
    /// 监听事件
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    public static void AddListener(string eventName, EventHandle handle)
    {
        Default.AddListener(eventName, handle);
    }

    /// <summary>
    /// 监听事件
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    public static void AddListener(string eventName, EventHandle<object> handle)
    {
        Default.AddListener(eventName, handle);
    }

    /// <summary>
    /// 监听事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="handle"></param>
    /// <typeparam name="T"></typeparam>
    public static void AddListener<T>(string eventName, EventHandle<T> handle)
    {
        Default.AddListener(eventName, handle);
    }

    /// <summary>
    /// 监听事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="handle"></param>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public static void AddListener<T1, T2>(string eventName, EventHandle<T1, T2> handle)
    {
        Default.AddListener(eventName, handle);
    }

    /// <summary>
    /// 监听事件
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="handle"></param>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    public static void AddListener<T1, T2, T3>(string eventName, EventHandle<T1, T2, T3> handle)
    {
        Default.AddListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    [Obsolete("已过时，请使用RemoveListener函数")]
    public static void RemoveHandle(string eventName, EventHandle handle)
    {
        RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    [Obsolete("已过时，请使用RemoveListener函数")]
    public static void RemoveHandle(string eventName, EventHandle<object> handle)
    {
        RemoveListener<object>(eventName, handle);
    }

    /// <summary>
    /// 移除监听
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="handle"></param>
    public static void RemoveListener(string eventName, Delegate handle)
    {
        Default.RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    public static void RemoveListener(string eventName, EventHandle handle)
    {
        Default.RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle">回调</param>
    public static void RemoveListener(string eventName, EventHandle<object> handle)
    {
        RemoveListener<object>(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle"></param>
    public static void RemoveListener<T>(string eventName, EventHandle<T> handle)
    {
        Default.RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle"></param>
    public static void RemoveListener<T1, T2>(string eventName, EventHandle<T1, T2> handle)
    {
        Default.RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件监听
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="handle"></param>
    public static void RemoveListener<T1, T2, T3>(string eventName, EventHandle<T1, T2, T3> handle)
    {
        Default.RemoveListener(eventName, handle);
    }

    /// <summary>
    /// 移除事件
    /// </summary>
    /// <param name="eventName"></param>
    public static void RemoveEvent(string eventName)
    {
        Default.RemoveEvent(eventName);
    }

    /// <summary>
    /// 移除所有事件
    /// </summary>
    public static void RemoveAllEvent()
    {
        Default.RemoveAllEvent();
    }
}